<?phpsession_start();?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Connexion admin</title>
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css">
    <link href="signin.css" rel="stylesheet">
	<script src="./jquery-1.10.2.min.js"></script>
	<script>
		$(document).ready(function() {
			if(typeof admin != 'undefined'){
				if(admin){
					window.location.href="index.php";
				}else{
					alert('Identifiant/Mot de passe incorrects');
				}
			}
		});
	</script>
  </head>

  <body>
  
  <?php
	if(isset($_POST['user']) and isset($_POST['password'])){
		
		$user=$_POST['user'];
		$pass=$_POST['password'];
		// Create connection
		$con=new PDO("mysql:dbname=djoa;host=127.0.0.1","root","");

		// Check connection
		if (mysqli_connect_errno($con))
		{
			echo "Failed to connect to MySQL: " . mysqli_connect_error();
		}
		?>
			<script>var admin=false;</script>
		<?php
		foreach ($con->query("SELECT * FROM admin") as $row ){
			if($user==$row[0] and $pass==$row[1]){
				
				$_SESSION['admin']='true';
				?>
				<script>var admin=true;</script>
				<?php
				break;
			}
		}
	}
?>

    <div class="container">

      <form class="form-signin" method="post" action="">
        <h2 class="form-signin-heading"><center>Connexion admin</center></h2>
        <input type="text" name="user" class="form-control" placeholder="Email address" required autofocus>
        <input type="password" name="password" class="form-control" placeholder="Password" required>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Valider</button>
		<a class="btn btn-lg btn-primary btn-block" href="index.php">Annuler</a>
      </form>

    </div> 
  </body>
</html>
